package com.yunmai.bookstore.service.impl;

import com.yunmai.bookstore.entity.User;
import com.yunmai.bookstore.mapper.UserMapper;
import com.yunmai.bookstore.result.Result;
import com.yunmai.bookstore.service.UserService;
import com.yunmai.bookstore.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static java.time.LocalDateTime.now;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public void register(User user) {

        // 密码加密
        String password= MD5Utils.getPwd(user.getPassword());



        userMapper.insert(user.getUsername(),password,user.getEmail(),user.getCreatedAt());
    }

    @Override
    public Result<User> getUserInfo(int userId) {
        Result<User> result = new Result<>();
        if(userMapper.selectByPrimaryKey(userId)!=null) {
            result.setData(userMapper.selectByPrimaryKey(userId));
            result.setCode(1);
        }
            else
            result.setCode(0);
        return result;
    }
}
